package cn.kgc;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;


public class MpGenarator {
    public static void main(String[] args) {
        String url = "jdbc:mysql:///db2106";
        String username = "root";
        String password = "123456";
        String author = "kgc";
        String outputDir = "D:\\idea2019\\IDEAWorkSpace\\hello-mp4\\src\\main\\java";
        String parent = "cn.kgc";
        String moduleName = "sys";
        String mapperXmlPath = "D:\\idea2019\\IDEAWorkSpace\\hello-mp4\\src\\main\\resources\\mybatis\\" + moduleName;
        String tableNames = "sys_user";
        String tablePrefix = "sys_";// 系统前缀




        FastAutoGenerator.create(url,username,password)
        .globalConfig(builder -> {
            builder.author(author) // 设置作者
                   //.enableSwagger() // 开启 swagger 模式
                    //.fileOverride() // 覆盖已生成文件
                    .outputDir(outputDir); // 指定输出目录
        })
                .packageConfig(builder -> {
                    builder.parent(parent) // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, mapperXmlPath)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tableNames) // 设置需要生成的表名
                            .addTablePrefix(tablePrefix); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
